
//----------------------------------------------------------------------------
// Copyright (c) 2011 Texas Instruments, Inc.
// This is an unpublished work created in the year stated above.
// Texas Instruments owns all rights in and to this work and
// intends to maintain and protect it as an unpublished copyright.
// In the event of either inadvertent or deliberate publication,
// the above stated date shall be treated as the year of first
// publication. In the event of such publication, Texas Instruments
// intends to enforce its rights in the work under the copyright
// laws as a published work.
//----------------------------------------------------------------------------
// Filename                : message_protocol.h
//
// Functional Description  : Common message protocol public interface
//
// Creation Date           : 2-Feb-2011
//
//----------------------------------------------------------------------------

#ifndef MESSAGE_PROTOCOL_H_
#define MESSAGE_PROTOCOL_H_

// 
// Default values
//

#define DEFAULT_MSG_ADMIN_STATE				0x01			// Admin: enabled, latched off: disabled
#define DEFAULT_MSG_ADDR_PTR				0xC800			// Default address for PEEK/POKE
#define DEFAULT_MSG_DEAD_TIME				50				// Default dead-time (2us)

// Protocol definitions for UART

// Status codes

#define MSG_STATUS_SUCCESS					0
#define MSG_STATUS_INVALID_CMD				1
#define MSG_STATUS_INVALID_CSUM				2

// Operation codes

#define MSG_OP_WRITE						0
#define MSG_OP_READ							1

// Device IDs

#define MSG_ID_SENSE_120_DRV92210			1
#define MSG_ID_SENSORLESS_120_DRV92211		2
#define MSG_ID_Vf_180_DRV92215				3

enum Command_Id
{
	// Configuration commands
	
	CmdDeviceType = 0,					// Device ID
	CmdFwVersion,						// Firmware Revision
	CmdAdminState,						// Administrative state
	CmdSetAddr,							// Set PEEK/POKE address
	CmdPeek,								// Peek at memory
	CmdPoke,								// Poke to memory
	CmdAfeWrite,							// Write character to AFE register
	CmdAfeRead,							// Read character from AFE register
	CmdSaveParams,						// Save parameters from RAM to FRAM
	CmdRestoreDefaults					// Restore factory defaults to FRAM
};

// External definitions

extern unsigned int MsgAdminState; 
extern unsigned int MsgAddrPtr;

// Additional External definitions - must be provided by application

extern unsigned int MsgDeviceId;
extern unsigned int MsgFwVersion;
extern unsigned char response_buffer[5];
// External function prototypes that application must supply

extern void message_protocol_init_app();									// Called after common message init
extern unsigned int message_handler_application_read();						// Returns pointer to data to read
extern unsigned int message_handler_application_write(unsigned int data);	// Data to write
extern void message_handler_application_save_parameters();					// Save any RAM parameters to FRAM
extern void message_handler_application_reset_defaults();					// Reset defaults to FRAM

// Function Prototypes

void msg_protocol_init();
void msg_protocol_reset_defaults();
void msg_protocol_save_parameters();
void msg_protocol_handler();

#endif /*MESSAGE_PROTOCOL_H_*/
